Skip to content

feat(memory): Add Valkey vector memory store#634

Open
edlng wants to merge 5 commits into
OpenBMB:mainfrom
edlng:add-valkey
Open

feat(memory): Add Valkey vector memory store#634
edlng wants to merge 5 commits into
OpenBMB:mainfrom
edlng:add-valkey

Conversation

@edlng

@edlng edlng commented Jun 8, 2026

Copy link
Copy Markdown

Summary

Adds a new valkey memory store type that uses Valkey Search's HNSW vector index for persistent, server-side memory with KNN retrieval. This gives users a self-hosted alternative to Mem0 for environments where cloud memory services aren't an option.

Issue

N/A

Changes

  • entity/configs/node/memory.py - New ValkeyMemoryConfig dataclass with from_dict parsing,
    validation (port range, db index, TTL), and FIELD_SPECS for the UI
  • runtime/node/agent/memory/valkey_memory.py - ValkeyMemory implementation: lazy-imports
    glide_sync, creates HNSW FT index on init, stores memories as Hashes with float32 embeddings, retrieves
    via FT.SEARCH KNN queries filtered by agent role, supports optional TTL via EXPIRE
  • runtime/node/agent/memory/builtin_stores.py - Registers valkey in the memory store registry with a
    lazy factory to avoid import-time dependency on valkey-glide-sync
  • pyproject.toml / uv.lock - Adds valkey-glide-sync>=2.4 as an optional dependency under
    [project.optional-dependencies] valkey
  • tests/test_valkey_memory.py - 738 lines of unit tests covering config parsing, validation edge cases,
    registry integration, tag sanitization, update/retrieve/count behavior, TTL handling, TLS/auth
    forwarding, and error paths
  • docs/user_guide/zh/modules/memory.md - Documents Valkey memory config fields, index behavior, and
    usage notes in the Chinese user guide
  • yaml_instance/demo_valkey_memory.yaml - Example workflow showing a memory-backed conversation agent
    using Valkey as the vector store

Tests

Full unit test suite in tests/test_valkey_memory.py. All Valkey interactions are mocked (no live server
required). Coverage includes:

  • Config parsing with valid/invalid inputs (port bounds, db bounds, TTL constraints)
  • Registry lookup and schema integration
  • ValkeyMemory instantiation, including idempotent index creation and error handling when the Search
    module is missing
  • update() with and without TTL, empty input short-circuit
  • retrieve() with threshold filtering, role-based FT.SEARCH queries, similarity ordering, empty query
    handling, and search errors
  • count_memories() success and failure paths
  • _sanitize_tag() edge cases

Blockers / Future work

  • No integration tests against a live Valkey instance yet (would need CI with valkey-bundle Docker image)

atao2004 and others added 5 commits June 5, 2026 08:40
* Add Valkey memory store scaffolding (config, registry, tests)

* Address PR feedback: port/db bounds, Docker note, collapse tests

* change required to True for port and host

* combine tests into one

* Revert host+port to required=False
Signed-off-by: Edward Liang <edward.liang@improving.com>
Signed-off-by: Edward Liang <edward.liang@improving.com>
@ferhimedamine

Copy link
Copy Markdown

Interesting approach with Valkey Search for HNSW. One thing to consider is whether the memory backend needs to do more than just vector KNN — in practice, agent memory benefits from hybrid retrieval (combining vector similarity with keyword/BM25 matching), importance scoring that adjusts based on access patterns, and per-agent namespace isolation.

Pure vector KNN works well for "find similar memories" but misses when the agent needs exact keyword matches (entity names, specific terms) that might not be well-represented in the embedding space. A hybrid approach covers both cases.

We went with RocksDB + HNSW + BM25 for this reason — the vector index handles semantic similarity while the fulltext index catches exact matches. Combined with access-weighted decay (less-used memories naturally deprioritize), it keeps the retrieval results relevant over time.

Self-hosted alternative if you want to compare approaches: https://github.com/Dakera-AI/dakera-deploy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants